local shuangxiong = fk.CreateSkill {
  name = "ls__shuangxiong",
  tags = { "Phase" }
}

Fk:loadTranslationTable{
  ["ls__shuangxiong"] = "双雄",
  [":ls__shuangxiong"] = "阶段技，你可<a href='ls__turnover'>翻面</a>，然后若中央区内的红色牌与黑色牌数量不同，则你弃置一张牌，回复1点体力。",
  ["ls__turnover"] = "双面武将翻面时，改为将武将牌替换为另一面的角色",
  ["#ls__shuangxiong-prompt"] = "双雄：你可翻面（变身）",
  ["#ls__shuangxiong-discard"] = "你可弃置一张牌，回复1点体力",

  ["$ls__shuangxiong_lssky__yanliang"] = "哈哈哈，先发制人！",
  ["$ls__shuangxiong_lssky__wenchou"] = "这般身手，也敢来战我？",
}

local DIY = require "packages/diy_utility/diy_utility"
local ls = require "packages/lvshi/utility"

shuangxiong:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

shuangxiong:addEffect("active", {
  anim_type = "support",
  prompt = "#ls__shuangxiong-prompt",
  card_filter = Util.FalseFunc,
  max_phase_use_time = 1,
  on_use = function(self, room, effect)
    local player = effect.from
    player:turnOver()
    local reds = #table.filter(DIY.getCenterCards(room), function (id)
      return Fk:getCardById(id).color == Card.Red
    end)
    local blacks = #table.filter(DIY.getCenterCards(room), function (id)
      return Fk:getCardById(id).color == Card.Black
    end)
    if reds ~= blacks and not player:isNude() then
      room:askToDiscard(player, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = shuangxiong.name,
        cancelable = false,
        prompt = "#ls__shuangxiong-discard",
      })
      if player:isAlive() and player:isWounded() then
        room:recover{
          who = player,
          num = 1,
          recoverBy = player,
          skillName = shuangxiong.name,
        }
      end
    end
  end
})

shuangxiong:addEffect(fk.BeforeTurnOver, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(shuangxiong.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    ls.turnOvertochange(player, shuangxiong)
    data.prevented = true
  end,
})

return shuangxiong
